/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package morenoapp.components.common;

import morenoapp.components.common.table.column.ColumnMeta;

/**
 *
 * @author root
 */
public abstract class AbstractCustomColumnsMorenoTableModel extends AbstractMorenoTableModel implements CustomColumnsTableModel{


    /*=== abstract part ===*/
    /**
     * Количество дополнительных столбцов перед матрицей.
     * @return
     */
    protected abstract int getFirstColumnsCount();

    protected abstract ColumnMeta getFirstColumnMeta(int index);

    protected abstract int getMiddleConlumnsCount();

    protected abstract ColumnMeta getMiddleColumnMeta(int index);

    protected abstract int getLastColumnsCount();

    protected abstract ColumnMeta getLastColumnMeta(int index);

    /*=== Custom methods ===*/
    @Override
    public ColumnMeta getColumnMeta(int index) {
        int restIndex = index;
        int firstColumnsCount = getFirstColumnsCount();
        if (restIndex < firstColumnsCount) {
            return getFirstColumnMeta(restIndex);
        }

        restIndex -= firstColumnsCount;
        int middleColumnsCount = getMiddleConlumnsCount();
        if (restIndex < middleColumnsCount) {
            return getMiddleColumnMeta(restIndex);
        }

        restIndex -= middleColumnsCount;
        return getLastColumnMeta(restIndex);
    }

    /* Implementation */
    @Override
    public int getColumnCount() {
        return getFirstColumnsCount() + getMiddleConlumnsCount() + getLastColumnsCount();
    }

    @Override
    public String getColumnName(int columnIndex) {
        return getColumnMeta(columnIndex).getName();
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return getColumnMeta(columnIndex).getType();
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return getColumnMeta(columnIndex).isEditable();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return getColumnMeta(columnIndex).getRowValue(rowIndex);
    }
}
